Skip to content

fix(cmd): fail fast when marking an unknown flag required#1771

Merged
AmanGIT07 merged 2 commits into
mainfrom
fix/cmd-required-flags
Jul 22, 2026
Merged

fix(cmd): fail fast when marking an unknown flag required#1771
AmanGIT07 merged 2 commits into
mainfrom
fix/cmd-required-flags

Conversation

@AmanGIT07

Copy link
Copy Markdown
Contributor

Summary

MarkFlagRequired returns an error only when the named flag is not defined on the command. All 49 call sites in cmd/ discarded it, so a mistyped or renamed flag name silently made the flag optional.

Changes

  • Add mustMarkRequired in cmd/flags.go: marks each named flag required and panics if the flag does not exist, naming the flag and the command
  • Replace all 49 cmd.MarkFlagRequired(...) calls across 11 files with mustMarkRequired(cmd, ...)
  • Add cmd/flags_test.go covering both paths

Technical Details

The helper runs during command construction, before flag parsing. A wrong flag name now crashes every CLI run and every go test ./cmd/ instead of shipping a command whose required flag is quietly optional. Current flag names are all valid: the existing cmd tests construct every command and none of the calls panic.

Test Plan

  • go test ./cmd/ passes
  • Build and type checking passes

MarkFlagRequired errors only when the named flag does not exist, and
every call site discarded that error, silently making the flag optional.
Route all calls through a helper that panics on an unknown name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
frontier Ready Ready Preview, Comment Jul 22, 2026 6:51am

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved required-flag validation consistency across many CLI commands, so missing required flags are detected and reported more reliably.
    • Updated preferences set validation to rely on required-flag checks for required inputs.
  • Tests
    • Added coverage ensuring required-flag registration behaves correctly, including cases where an invalid flag name is provided.

Walkthrough

Adds and tests a shared mustMarkRequired helper, then replaces direct Cobra required-flag calls across resource and auxiliary CLI commands. preferences set also marks name and value as required and removes their prior runtime validation.

Changes

Required flag validation

Layer / File(s) Summary
Helper implementation and validation
cmd/flags.go, cmd/flags_test.go
Adds mustMarkRequired with panic handling for invalid flags and tests valid and unknown flag behavior.
Resource command required flags
cmd/group.go, cmd/organization.go, cmd/permission.go, cmd/policy.go, cmd/project.go, cmd/role.go, cmd/user.go
Routes resource command file and header required-flag registration through the shared helper.
Auxiliary command required flags
cmd/namespace.go, cmd/preferences.go, cmd/reconcile.go, cmd/seed.go
Routes auxiliary required-flag registration through the shared helper; preferences set also requires name and value.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coveralls

coveralls commented Jul 17, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29898091278

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.1%) to 46.233%

Details

  • Coverage increased (+0.1%) from the base build.
  • Patch coverage: 53 of 53 lines across 12 files are fully covered (100%).
  • 315 coverage regressions across 8 files.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

315 previously-covered lines in 8 files lost coverage.

File Lines Losing Coverage Coverage
core/membership/service.go 171 81.9%
internal/bootstrap/schema/schema.go 52 16.67%
internal/reconcile/permission_reconciler.go 22 75.26%
internal/reconcile/role_reconciler.go 22 82.91%
internal/reconcile/platformuser_reconciler.go 18 82.95%
internal/reconcile/preference_reconciler.go 17 77.42%
internal/reconcile/reconcile.go 11 86.81%
internal/reconcile/platformuser.go 2 97.98%

Coverage Stats

Coverage Status
Relevant Lines: 38464
Covered Lines: 17783
Line Coverage: 46.23%
Coverage Strength: 13.88 hits per line

💛 - Coveralls

Comment thread cmd/preferences.go Outdated
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8eb837f8-daf8-4393-a886-660ac72451f8

📥 Commits

Reviewing files that changed from the base of the PR and between e26a581 and 7d202a3.

📒 Files selected for processing (1)
  • cmd/preferences.go

Comment thread cmd/preferences.go
@AmanGIT07
AmanGIT07 merged commit bdc2a59 into main Jul 22, 2026
8 checks passed
@AmanGIT07
AmanGIT07 deleted the fix/cmd-required-flags branch July 22, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants